home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / Select.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-11-16  |  11.3 KB  |  268 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Bladex
  5. import Reference
  6. import netgame
  7. TRUE = 1 == 1
  8. FALSE = 1 != 1
  9. if netgame.GetNetState() == 2:
  10.     MAX_VISIBLE_ENEMIES_DISTANCE = 80000
  11.     MAX_SELECTION_DISTANCE = 8000.0
  12. else:
  13.     MAX_SELECTION_DISTANCE = 8000.0
  14. AUTOSELECT_PERIOD = 0.2
  15. Gpj = None
  16.  
  17. def SqDistanceToGpj(entity):
  18.     return Gpj.SQDistance2(entity)
  19.  
  20.  
  21. def GetSelectionData(entity_name):
  22.     entity = Bladex.GetEntity(entity_name)
  23.     if Reference.EntitiesSelectionData.has_key(entity_name):
  24.         return Reference.EntitiesSelectionData[entity_name]
  25.     elif Reference.DefaultSelectionData.has_key(entity.Kind):
  26.         return Reference.DefaultSelectionData[entity.Kind]
  27.     else:
  28.         return None
  29.  
  30.  
  31. def IsValidForSelection(entity_entry):
  32.     if entity_entry[1]:
  33.         entity_name = entity_entry[0]
  34.         entity = Bladex.GetEntity(entity_name)
  35.         if entity:
  36.             parent_name = entity.Parent
  37.             if parent_name != None:
  38.                 if parent_name != '':
  39.                     parent = Bladex.GetEntity(parent_name)
  40.                     if parent.Person:
  41.                         return FALSE
  42.                     
  43.                 
  44.             
  45.         else:
  46.             return FALSE
  47.         if SqDistanceToGpj(entity) > entity_entry[1][1] * entity_entry[1][1]:
  48.             return FALSE
  49.         
  50.     else:
  51.         return FALSE
  52.     return TRUE
  53.  
  54.  
  55. def GetMoreInterestingEntity(pj, list):
  56.     target = None
  57.     priority = 0.0
  58.     sqdistance = MAX_SELECTION_DISTANCE * MAX_SELECTION_DISTANCE
  59.     for x in list:
  60.         pass
  61.     
  62.     return target
  63.  
  64.  
  65. def GetNextMoreInterestingEntity(pj, list, sentry):
  66.     target = None
  67.     priority = 0.0
  68.     sqdistance = MAX_SELECTION_DISTANCE * MAX_SELECTION_DISTANCE
  69.     spriority = sentry[1][0]
  70.     ssqdistance = SqDistanceToGpj(Bladex.GetEntity(sentry[0]))
  71.     for x in list:
  72.         if priority < x[1][0] and priority == x[1][0] and sqdistance > SqDistanceToGpj(Bladex.GetEntity(x[0])):
  73.             if spriority > x[1][0] and spriority == x[1][0] and ssqdistance < SqDistanceToGpj(Bladex.GetEntity(x[0])):
  74.                 target = x
  75.                 priority = x[1][0]
  76.                 sqdistance = SqDistanceToGpj(Bladex.GetEntity(x[0]))
  77.             
  78.         
  79.     
  80.     return target
  81.  
  82.  
  83. def GetFromList(entity_entry, list):
  84.     for x in list:
  85.         pass
  86.     
  87.     return None
  88.  
  89.  
  90. def GetNextFromList(entity_entry, list):
  91.     for x in range(1, len(list)):
  92.         pass
  93.     
  94.     return None
  95.  
  96.  
  97. def SelectNext(pj):
  98.     global Gpj
  99.     Gpj = pj
  100.     head_pos = pj.Rel2AbsPoint(0.0, 0.0, 0.0, 'Head')
  101.     pj_dir = pj.Rel2AbsVector(0.0, -1.0, 0.0)
  102.     list = Bladex.GetObjectEntitiesVisibleFrom(head_pos, MAX_SELECTION_DISTANCE, pj_dir, 0.0)
  103.     list = map(None, list, map(GetSelectionData, list))
  104.     list = filter(IsValidForSelection, list)
  105.     if pj.Data.selection_locked and pj.Data.selected_entity:
  106.         target = GetFromList(pj.Data.selected_entity, list)
  107.         if not target:
  108.             pj.Data.selection_locked = FALSE
  109.             target = GetMoreInterestingEntity(pj, list)
  110.         else:
  111.             target = GetNextMoreInterestingEntity(pj, list, pj.Data.selected_entity)
  112.             if not target:
  113.                 target = GetMoreInterestingEntity(pj, list)
  114.             
  115.     else:
  116.         pj.Data.selection_locked = FALSE
  117.         target = GetMoreInterestingEntity(pj, list)
  118.     pj.Data.selected_entity = target
  119.     if target:
  120.         pj.LookAtEntity(target[0])
  121.     else:
  122.         pj.LookAtEntity('')
  123.         pj.StopLooking()
  124.  
  125.  
  126. def AutoSelect(pj):
  127.     global Gpj
  128.     Gpj = pj
  129.     head_pos = pj.Rel2AbsPoint(0.0, 0.0, 0.0, 'Head')
  130.     pj_dir = pj.Rel2AbsVector(0.0, -1.0, 0.0)
  131.     list = Bladex.GetObjectEntitiesVisibleFrom(head_pos, MAX_SELECTION_DISTANCE, pj_dir, 0.0)
  132.     list = map(None, list, map(GetSelectionData, list))
  133.     list = filter(IsValidForSelection, list)
  134.     if pj.Data.selection_locked and pj.Data.selected_entity:
  135.         target = GetFromList(pj.Data.selected_entity, list)
  136.         if not target:
  137.             pj.Data.selection_locked = FALSE
  138.             target = GetMoreInterestingEntity(pj, list)
  139.         
  140.     else:
  141.         pj.Data.selection_locked = FALSE
  142.         target = GetMoreInterestingEntity(pj, list)
  143.     pj.Data.selected_entity = target
  144.  
  145.  
  146. def GetEnemiesScorerData(entity_name):
  147.     entity = Bladex.GetEntity(entity_name)
  148.     if Reference.EnemiesScorerData.has_key(entity_name):
  149.         return Reference.EnemiesScorerData[entity_name]
  150.     elif Reference.EnemiesDefaultScorerData.has_key(entity.MeshName):
  151.         return Reference.EnemiesDefaultScorerData[entity.MeshName]
  152.     elif Reference.EnemiesDefaultScorerData.has_key(entity.Kind):
  153.         return Reference.EnemiesDefaultScorerData[entity.Kind]
  154.     else:
  155.         return None
  156.  
  157.  
  158. def Distance2Pj(enemy_entry):
  159.     enemy = Bladex.GetEntity(enemy_entry[0])
  160.     return Gpj.SQDistance2(enemy)
  161.  
  162.  
  163. def ShortEnemiesList(pj):
  164.     global Gpj
  165.     Gpj = pj
  166.     list = pj.Data.visible_enemies
  167.  
  168.  
  169. def SelectNextEnemy(pj):
  170.     chartype = Bladex.GetCharType(pj.CharType, pj.CharTypeExt)
  171.     MAX_VISIBLE_ENEMIES_DISTANCE = chartype.MaxCombatDist
  172.     head_pos = pj.Rel2AbsPoint(0.0, 0.0, 0.0)
  173.     pj_dir = pj.Rel2AbsVector(0.0, -1.0, 0.0)
  174.     list = Bladex.GetEnemiesVisibleFrom(head_pos, MAX_VISIBLE_ENEMIES_DISTANCE, pj_dir, 0.0)
  175.     list = map(None, list, map(GetEnemiesScorerData, list))
  176.     pj.Data.visible_enemies = list
  177.     if len(pj.Data.visible_enemies):
  178.         ShortEnemiesList(pj)
  179.         if pj.Data.enemy_locked and pj.Data.selected_enemy:
  180.             target = GetNextFromList(pj.Data.selected_enemy, list)
  181.             if not target:
  182.                 pj.Data.enemy_locked = FALSE
  183.                 pj.Data.selected_enemy = pj.Data.visible_enemies[0]
  184.             else:
  185.                 pj.Data.selected_enemy = target
  186.         else:
  187.             pj.Data.selected_enemy = pj.Data.visible_enemies[0]
  188.     else:
  189.         pj.Data.enemy_locked = FALSE
  190.         pj.Data.selected_enemy = None
  191.  
  192. import pdb
  193.  
  194. def GetVisibleEnemies(pj):
  195.     head_pos = pj.Rel2AbsPoint(0.0, 0.0, 0.0)
  196.     if (pj.AnimName == 'g_back' or pj.AnimName == 'g2h_back') and pj.AnmPos > 0.6:
  197.         dir_y = 1.0
  198.     else:
  199.         dir_y = -1.0
  200.     chartype = Bladex.GetCharType(pj.CharType, pj.CharTypeExt)
  201.     MAX_VISIBLE_ENEMIES_DISTANCE = chartype.MaxCombatDist
  202.     pj_dir = pj.Rel2AbsVector(0.0, dir_y, 0.0)
  203.     list = Bladex.GetEnemiesVisibleFrom(head_pos, MAX_VISIBLE_ENEMIES_DISTANCE, pj_dir, 0.0)
  204.     list = map(None, list, map(GetEnemiesScorerData, list))
  205.     pj.Data.visible_enemies = list
  206.     if len(pj.Data.visible_enemies):
  207.         ShortEnemiesList(pj)
  208.         if pj.Data.enemy_locked and pj.Data.selected_enemy:
  209.             target = GetFromList(pj.Data.selected_enemy, list)
  210.             if not target:
  211.                 pj.Data.enemy_locked = FALSE
  212.                 pj.Data.selected_enemy = pj.Data.visible_enemies[0]
  213.             
  214.         else:
  215.             pj.Data.selected_enemy = pj.Data.visible_enemies[0]
  216.     else:
  217.         pj.Data.enemy_locked = FALSE
  218.         pj.Data.selected_enemy = None
  219.  
  220.  
  221. def PeriodicAutoSelect(pj_name, look_for_enemies = 1, autoselect_period = AUTOSELECT_PERIOD):
  222.     import DefaultSelectionData
  223.     pj = Bladex.GetEntity(pj_name)
  224.     if pj and pj.Data.auto_select:
  225.         AutoSelect(pj)
  226.         GetVisibleEnemies(pj)
  227.         if pj.Data.selected_enemy:
  228.             pj.LookAtEntity(pj.Data.selected_enemy[0])
  229.         elif pj.Data.selected_entity:
  230.             pj.LookAtEntity(pj.Data.selected_entity[0])
  231.             if pj.Data.selected_entity and not (pj.Data.selection_locked) and pj.Data.selected_entity[1][0] > 6:
  232.                 DefaultSelectionData.SelectObject()
  233.             
  234.         else:
  235.             pj.LookAtEntity('')
  236.             pj.StopLooking()
  237.         Bladex.AddScheduledFunc(Bladex.GetTime() + autoselect_period, PeriodicAutoSelect, (pj_name, look_for_enemies, autoselect_period), 'PeriodicAutoSelect' + pj_name)
  238.     
  239.  
  240.  
  241. def AutoSelectInAttack(EntityName):
  242.     import DefaultSelectionData
  243.     pj = Bladex.GetEntity(EntityName)
  244.     if pj and not (pj.Data.NPC) and Bladex.GetAutoEngageCombat():
  245.         if not (pj.InCombat):
  246.             DefaultSelectionData.SelectEnemy()
  247.         
  248.     
  249.  
  250.  
  251. def TurnOnAutoSelect(pj_name, look_for_enemies = 1, autoselect_period = AUTOSELECT_PERIOD):
  252.     pj = Bladex.GetEntity(pj_name)
  253.     pj.Data.selected_entity = None
  254.     pj.Data.selection_locked = FALSE
  255.     pj.Data.visible_enemies = ()
  256.     pj.Data.selected_enemy = None
  257.     pj.Data.enemy_locked = FALSE
  258.     pj.Data.auto_select = TRUE
  259.     Bladex.RemoveScheduledFunc('TurnOnAutoSelect' + pj_name)
  260.     Bladex.RemoveScheduledFunc('PeriodicAutoSelect' + pj_name)
  261.     Bladex.AddScheduledFunc(Bladex.GetTime() + autoselect_period, PeriodicAutoSelect, (pj_name, look_for_enemies, autoselect_period), 'TurnOnAutoSelect' + pj_name)
  262.  
  263.  
  264. def TurnOffAutoSelect(pj_name):
  265.     pj = Bladex.GetEntity(pj_name)
  266.     pj.Data.auto_select = FALSE
  267.  
  268.